app.controller("order", ['$scope', '$stateParams', '$http', '$window', '$cookieStore', '$state', '$filter', function ($scope, $stateParams, $http, $window, $cookieStore, $state, $filter) {

    if ($stateParams.title == 'order') {
        $window.document.title = '订单详情'
    }
    // 判断登录函数
    $scope.login()

    $(function () {
        $('#useridImg').width($window.screen.width * .93);
        $('#useridImg').height($window.screen.width * .93 / 1.58);
        $('#useridImg2').width($window.screen.width * .93);
        $('#useridImg2').height($window.screen.width * .93 / 1.58);
    })
    // 积分
    $scope.integralList = [
        100, 200, 300, 400, 500, '取消'
    ]
    // 显示的积分
    $scope.showInteg = '点击选择';

    // 房间信息
    $http({
        method: 'post',
        url: $scope.httptit + '/index/order/detail.html',
        data: {
            id: $stateParams.id
        },
        dataType: 'json',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        transformRequest: $scope.changeData
    }).then(function successCallback(response) {
        console.log(response.data);
        $scope.orderData = response.data.data;       
        if(response.data.data.deposit==0){
            $scope.orderData.price=response.data.data.money+response.data.data.cash
 
        }else{
            $scope.orderData.price=response.data.data.money
        }
        //         // 点击选择积分
        $scope.getInteg = function (val) {
            if (val != '取消') {
                if (val > $scope.orderData.integral) {
                    $.alert({
                        title: '错误提示',
                        text: '可用积分不足，请重新选择',
                    });
                } else {
                    $scope.showInteg =  val ;
                    if(response.data.data.deposit==0){
                        console.log('122')
                        $scope.orderData.price=response.data.data.money+response.data.data.cash-val/100;
                    }else{
                        $scope.orderData.price=response.data.data.money-val/100;
                    }
                }
            } else {
                $scope.integral = false;
            }
        }

        if(response.data.deposit==0){
            $scope.price=response.data.data.money+200;
        }else{
            $scope.price=response.data.data.money;
        }
    }, function errorCallback(response) {
    });

    $scope.subOrder = function (val) {
        var integ = 0;
        if (!val) {
            $.alert({
                title: '错误提示',
                text: '请记得勾选房东合同',
            });
        } else {
            if ($scope.showInteg == '点击选择') {
                integ = 0
            } else {
                integ = $scope.showInteg;
            }

            console.log(integ)
            window.location.href = 'http://www.andthink.cn/gongyu/index.php/index/wx/pay.html?id=' + $stateParams.id+'&integ='+integ
        }
    }
}]);
